{{#models}}{{#model}}
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "{{classname}}.h"

{{#isEnum}}
    char* OpenAPI_{{classname}}_ToString(OpenAPI_{{classVarName}}_e {{classname}})
    {
        const char *{{classname}}Array[] =  { "NULL"{{#allowableValues}}{{#enumVars}}, "{{{value}}}"{{/enumVars}}{{/allowableValues}} };
        size_t sizeofArray = sizeof({{classname}}Array) / sizeof({{classname}}Array[0]);
        if ({{classname}} < sizeofArray)
            return (char *){{classname}}Array[{{classname}}];
        else
            return (char *)"Unknown";
    }

    OpenAPI_{{classVarName}}_e OpenAPI_{{classname}}_FromString(char* {{classname}})
    {
        int stringToReturn = 0;
        const char *{{classname}}Array[] =  { "NULL"{{#allowableValues}}{{#enumVars}}, "{{{value}}}"{{/enumVars}}{{/allowableValues}} };
        size_t sizeofArray = sizeof({{classname}}Array) / sizeof({{classname}}Array[0]);
        while (stringToReturn < sizeofArray) {
            if (strcmp({{classname}}, {{classname}}Array[stringToReturn]) == 0) {
                return stringToReturn;
            }
            stringToReturn++;
        }
        return 0;
    }
{{/isEnum}}
{{^isEnum}}
{{#vars}}
    {{^isContainer}}
        {{#isPrimitiveType}}
            {{#isEnum}}
                char *OpenAPI_{{name}}{{classname}}_ToString(OpenAPI_{{classVarName}}_{{name}}_e {{name}})
                {
                    const char *{{name}}Array[] =  { "NULL"{{#allowableValues}}{{#enumVars}}, "{{{value}}}"{{/enumVars}}{{/allowableValues}} };
                    size_t sizeofArray = sizeof({{name}}Array) / sizeof({{name}}Array[0]);
                    if ({{name}} < sizeofArray)
                        return (char *){{name}}Array[{{name}}];
                    else
                        return (char *)"Unknown";
                }

                OpenAPI_{{classVarName}}_{{name}}_e OpenAPI_{{name}}{{classname}}_FromString(char* {{name}})
                {
                    int stringToReturn = 0;
                    const char *{{name}}Array[] =  { "NULL"{{#allowableValues}}{{#enumVars}}, "{{{value}}}"{{/enumVars}}{{/allowableValues}} };
                    size_t sizeofArray = sizeof({{name}}Array) / sizeof({{name}}Array[0]);
                    while (stringToReturn < sizeofArray) {
                        if (strcmp({{name}}, {{name}}Array[stringToReturn]) == 0) {
                            return stringToReturn;
                        }
                        stringToReturn++;
                    }
                    return 0;
                }
            {{/isEnum}}
        {{/isPrimitiveType}}
    {{/isContainer}}
{{/vars}}
OpenAPI_{{classname}}_t *OpenAPI_{{classname}}_create(
{{#vars}}
    {{^isContainer}}
        {{^isPrimitiveType}}
            {{#isEnum}}
                OpenAPI_{{datatype}}_e {{name}}{{#hasMore}},{{/hasMore}}
            {{/isEnum}}
            {{^isEnum}}
                {{#isModel}}
                    OpenAPI_{{datatype}}_t *{{name}}{{#hasMore}},{{/hasMore}}
                {{/isModel}}
                {{#isUuid}}
                    {{datatype}} *{{name}}{{#hasMore}},{{/hasMore}}
                {{/isUuid}}
                {{#isEmail}}
                    {{datatype}} *{{name}}{{#hasMore}},{{/hasMore}}
                {{/isEmail}}
                {{#isFreeFormObject}}
                    OpenAPI_{{datatype}}_t *{{name}}{{#hasMore}},{{/hasMore}}
                {{/isFreeFormObject}}
            {{/isEnum}}
        {{/isPrimitiveType}}
        {{#isPrimitiveType}}
            {{#isEnum}}
                OpenAPI_{{classVarName}}_{{name}}_e {{name}}{{#hasMore}},{{/hasMore}}
            {{/isEnum}}
            {{^isEnum}}
                {{#isNumeric}}
                    {{datatype}} {{name}}{{#hasMore}},{{/hasMore}}
                {{/isNumeric}}
                {{#isBoolean}}
                    {{datatype}} {{name}}{{#hasMore}},{{/hasMore}}
                {{/isBoolean}}
                {{#isString}}
                    {{datatype}} *{{name}}{{#hasMore}},{{/hasMore}}
                {{/isString}}
            {{/isEnum}}
            {{#isByteArray}}
                {{datatype}} {{name}}{{#hasMore}},{{/hasMore}}
            {{/isByteArray}}
            {{#isBinary}}
                OpenAPI_{{datatype}} {{name}}{{#hasMore}},{{/hasMore}}
            {{/isBinary}}
            {{#isDate}}
                {{datatype}} *{{name}}{{#hasMore}},{{/hasMore}}
            {{/isDate}}
            {{#isDateTime}}
                {{datatype}} *{{name}}{{#hasMore}},{{/hasMore}}
            {{/isDateTime}}
        {{/isPrimitiveType}}
    {{/isContainer}}
    {{#isContainer}}
        {{#isListContainer}}
            OpenAPI_{{datatype}}_t *{{name}}{{#hasMore}},{{/hasMore}}
        {{/isListContainer}}
        {{#isMapContainer}}
            OpenAPI_{{datatype}} {{name}}{{#hasMore}},{{/hasMore}}
        {{/isMapContainer}}
    {{/isContainer}}
{{/vars}})
{
    OpenAPI_{{classname}}_t *{{classname}}_local_var = OpenAPI_malloc(sizeof(OpenAPI_{{classname}}_t));
    if (!{{classname}}_local_var) {
        return NULL;
    }
{{#vars}}
    {{classname}}_local_var->{{{name}}} = {{{name}}};
{{/vars}}

    return {{classname}}_local_var;
}

void OpenAPI_{{classname}}_free(OpenAPI_{{classname}}_t *{{classname}})
{
    if (NULL == {{classname}}) {
        return ;
    }
    OpenAPI_lnode_t *node;
{{#vars}}
    {{^isContainer}}
        {{^isPrimitiveType}}
            {{^isEnum}}
                {{#isModel}}
                    OpenAPI_{{{complexType}}}_free({{{classname}}}->{{{name}}});
                {{/isModel}}
                {{#isUuid}}
                    ogs_free({{{classname}}}->{{{name}}});
                {{/isUuid}}
                {{#isEmail}}
                    ogs_free({{{classname}}}->{{{name}}});
                {{/isEmail}}
                {{#isFreeFormObject}}
                    OpenAPI_object_free({{{classname}}}->{{{name}}});
                {{/isFreeFormObject}}
            {{/isEnum}}
        {{/isPrimitiveType}}
        {{#isPrimitiveType}}
            {{^isEnum}}
                {{#isString}}
                    ogs_free({{{classname}}}->{{{name}}});
                {{/isString}}
            {{/isEnum}}
            {{#isBinary}}
                ogs_free({{{classname}}}->{{{name}}}->data);
            {{/isBinary}}
            {{#isDate}}
                ogs_free({{{classname}}}->{{{name}}});
            {{/isDate}}
            {{#isDateTime}}
                ogs_free({{{classname}}}->{{{name}}});
            {{/isDateTime}}
        {{/isPrimitiveType}}
    {{/isContainer}}
    {{#isContainer}}
        {{#isListContainer}}
            {{#isPrimitiveType}}
                {{^isEnum}}
                    OpenAPI_list_for_each({{classname}}->{{name}}, node) {
                        ogs_free(node->data);
                    }
                {{/isEnum}}
                OpenAPI_list_free({{classname}}->{{name}});
            {{/isPrimitiveType}}
            {{^isPrimitiveType}}
                {{^isEnum}}
                    OpenAPI_list_for_each({{classname}}->{{name}}, node) {
                        OpenAPI_{{complexType}}_free(node->data);
                    }
                {{/isEnum}}
                OpenAPI_list_free({{classname}}->{{name}});
            {{/isPrimitiveType}}
        {{/isListContainer}}
        {{#isMapContainer}}
            {{#isPrimitiveType}}
                OpenAPI_list_for_each({{classname}}->{{name}}, node) {
                    OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*)node->data;
                    ogs_free(localKeyValue->value);
                    ogs_free(localKeyValue);
                }
                OpenAPI_list_free({{classname}}->{{name}});
            {{/isPrimitiveType}}
            {{^isPrimitiveType}}
                OpenAPI_list_for_each({{classname}}->{{name}}, node) {
                    OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*)node->data;
                    OpenAPI_{{complexType}}_free(localKeyValue->value);
                    ogs_free(localKeyValue);
                }
                OpenAPI_list_free({{classname}}->{{name}});
            {{/isPrimitiveType}}
        {{/isMapContainer}}
    {{/isContainer}}
{{/vars}}
    ogs_free({{classname}});
}

cJSON *OpenAPI_{{classname}}_convertToJSON(OpenAPI_{{classname}}_t *{{classname}})
{
    cJSON *item = NULL;

    if ({{classname}} == NULL) {
        ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
        return NULL;
    }

    item = cJSON_CreateObject();
{{#vars}}
    {{#required}}
        {{^isBoolean}}
            if (!{{{classname}}}->{{{name}}}) {
                ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                goto end;
            }
        {{/isBoolean}}
    {{/required}}
    {{^required}}
        if ({{{classname}}}->{{{name}}}) {
    {{/required}}
    {{^isContainer}}
        {{#isPrimitiveType}}
            {{#isEnum}}
                if (cJSON_AddStringToObject(item, "{{{baseName}}}", OpenAPI_{{{name}}}{{classname}}_ToString({{{classname}}}->{{{name}}})) == NULL) {
                    ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                    goto end;
                }
            {{/isEnum}}
            {{^isEnum}}
                {{#isNumeric}}
                    if (cJSON_AddNumberToObject(item, "{{{baseName}}}", {{{classname}}}->{{{name}}}) == NULL) {
                        ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                        goto end;
                    }
                {{/isNumeric}}
                {{#isBoolean}}
                    if (cJSON_AddBoolToObject(item, "{{{baseName}}}", {{{classname}}}->{{{name}}}) == NULL) {
                        ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                        goto end;
                    }
                {{/isBoolean}}
                {{#isString}}
                if (cJSON_AddStringToObject(item, "{{{baseName}}}", {{{classname}}}->{{{name}}}) == NULL) {
                    ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                    goto end;
                }
            {{/isString}}
            {{/isEnum}}
            {{#isByteArray}}
                if (cJSON_AddNumberToObject(item, "{{{baseName}}}", {{{classname}}}->{{{name}}}) == NULL) {
                    ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                    goto end;
                }
            {{/isByteArray}}
            {{#isBinary}}
                char* encoded_str_{{{name}}} = OpenAPI_base64encode({{{classname}}}->{{{name}}}->data,{{{classname}}}->{{{name}}}->len);
                if (cJSON_AddStringToObject(item, "{{{baseName}}}", encoded_str_{{{name}}}) == NULL) {
                    ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                    goto end;
                }
                ogs_free(encoded_str_{{{name}}});
            {{/isBinary}}
            {{#isDate}}
                if (cJSON_AddStringToObject(item, "{{{baseName}}}", {{{classname}}}->{{{name}}}) == NULL) {
                    ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                    goto end;
                }
            {{/isDate}}
            {{#isDateTime}}
                if (cJSON_AddStringToObject(item, "{{{baseName}}}", {{{classname}}}->{{{name}}}) == NULL) {
                    ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                    goto end;
                }
            {{/isDateTime}}
        {{/isPrimitiveType}}
        {{^isPrimitiveType}}
            {{#isEnum}}
                if (cJSON_AddStringToObject(item, "{{{baseName}}}", OpenAPI_{{{complexType}}}_ToString({{{classname}}}->{{{name}}})) == NULL) {
                    ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                    goto end;
                }
            {{/isEnum}}
            {{^isEnum}}
                {{#isModel}}
                    cJSON *{{{name}}}_local_JSON = OpenAPI_{{complexType}}{{#isFreeFormObject}}object{{/isFreeFormObject}}_convertToJSON({{{classname}}}->{{{name}}});
                    if ({{{name}}}_local_JSON == NULL) {
                        ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                        goto end;
                    }
                    cJSON_AddItemToObject(item, "{{{baseName}}}", {{{name}}}_local_JSON);
                    if (item->child == NULL) {
                        ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                        goto end;
                    }
                {{/isModel}}
                {{#isUuid}}
                    if (cJSON_AddStringToObject(item, "{{{baseName}}}", {{{classname}}}->{{{name}}}) == NULL) {
                        ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                        goto end;
                    }
                {{/isUuid}}
                {{#isEmail}}
                    if (cJSON_AddStringToObject(item, "{{{baseName}}}", {{{classname}}}->{{{name}}}) == NULL) {
                        ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                        goto end;
                    }
                {{/isEmail}}
                {{#isFreeFormObject}}
                    cJSON *{{{name}}}_object = OpenAPI_object_convertToJSON({{{classname}}}->{{{name}}});
                    if ({{{name}}}_object == NULL) {
                        ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                        goto end;
                    }
                    cJSON_AddItemToObject(item, "{{{baseName}}}", {{{name}}}_object);
                    if (item->child == NULL) {
                        ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                        goto end;
                    }
                {{/isFreeFormObject}}
            {{/isEnum}}
        {{/isPrimitiveType}}
    {{/isContainer}}
    {{#isContainer}}
        {{#isListContainer}}
            {{#isPrimitiveType}}
                {{^isEnum}}
                    cJSON *{{{name}}} = cJSON_AddArrayToObject(item, "{{{baseName}}}");
                    if ({{{name}}} == NULL) {
                        ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                        goto end;
                    }

                    OpenAPI_lnode_t *{{{name}}}_node;
                    OpenAPI_list_for_each({{{classname}}}->{{{name}}}, {{{name}}}_node)  {
                    {{#items}}
                        {{#isString}}
                            if (cJSON_AddStringToObject({{{name}}}, "", (char*){{{name}}}_node->data) == NULL) {
                                ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                                goto end;
                            }
                        {{/isString}}
                        {{#isBoolean}}
                            if (cJSON_AddBoolToObject({{{name}}}, "", *(cJSON_bool *){{{name}}}_node->data) == NULL) {
                                ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                                goto end;
                            }
                        {{/isBoolean}}
                        {{#isNumeric}}
                            if (cJSON_AddNumberToObject({{{name}}}, "", *(double *){{{name}}}_node->data) == NULL) {
                                ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                                goto end;
                            }
                        {{/isNumeric}}
                    {{/items}}
                    }
                {{/isEnum}}
            {{/isPrimitiveType}}
            {{^isPrimitiveType}}
                {{^isEnum}}
                    cJSON *{{{name}}}List = cJSON_AddArrayToObject(item, "{{{baseName}}}");
                    if ({{{name}}}List == NULL) {
                        ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                        goto end;
                    }

                    OpenAPI_lnode_t *{{{name}}}_node;
                    if ({{{classname}}}->{{{name}}}) {
                        OpenAPI_list_for_each({{classname}}->{{{name}}}, {{{name}}}_node) {
                            cJSON *itemLocal = OpenAPI_{{complexType}}_convertToJSON({{#isEnum}}{{#items}}(OpenAPI_{{classVarName}}_{{name}}_e){{/items}}{{/isEnum}}{{{name}}}_node->data);
                            if (itemLocal == NULL) {
                                ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                                goto end;
                            }
                            cJSON_AddItemToArray({{{name}}}List, itemLocal);
                        }
                    }
                {{/isEnum}}
                {{#isEnum}}
                    cJSON *{{{name}}} = cJSON_AddArrayToObject(item, "{{{baseName}}}");
                    if ({{{name}}} == NULL) {
                        ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                        goto end;
                    }
                    OpenAPI_lnode_t *{{{name}}}_node;
                    OpenAPI_list_for_each({{classname}}->{{{name}}}, {{{name}}}_node) {
                        if (cJSON_AddStringToObject({{{name}}}, "", OpenAPI_{{{complexType}}}_ToString((OpenAPI_{{{complexType}}}_e){{{name}}}_node->data)) == NULL) {
                            ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                            goto end;
                        }
                    }
                {{/isEnum}}
            {{/isPrimitiveType}}
        {{/isListContainer}}
        {{#isMapContainer}}
            cJSON *{{{name}}} = cJSON_AddObjectToObject(item, "{{{baseName}}}");
            if ({{{name}}} == NULL) {
                ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                goto end;
            }
            cJSON *localMapObject = {{{name}}};
            OpenAPI_lnode_t *{{{name}}}_node;
            if ({{{classname}}}->{{{name}}}) {
                OpenAPI_list_for_each({{{classname}}}->{{{name}}}, {{{name}}}_node) {
                    OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*){{{name}}}_node->data;
                {{#isPrimitiveType}}
                    {{#isString}}
                    if (cJSON_AddStringToObject(localMapObject, localKeyValue->key, (char*)localKeyValue->value) == NULL) {
                        ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                        goto end;
                    }
                    {{/isString}}
                    {{#isNumeric}}
                    if (cJSON_AddNumberToObject(localMapObject, localKeyValue->key, *(double *)localKeyValue->value) == NULL) {
                        ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                        goto end;
                    }
                    {{/isNumeric}}
                    {{#isBoolean}}
                    if (cJSON_AddBoolToObject(localMapObject, localKeyValue->key, *(cJSON_bool *)localKeyValue->value) == NULL) {
                        ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                        goto end;
                    }
                    {{/isBoolean}}
                {{/isPrimitiveType}}
                {{^isPrimitiveType}}
                    cJSON *itemLocal = OpenAPI_{{complexType}}_convertToJSON(localKeyValue->value);
                    if (itemLocal == NULL) {
                        ogs_error("OpenAPI_{{classname}}_convertToJSON() failed [{{{name}}}]");
                        goto end;
                    }
                    cJSON_AddItemToObject({{{name}}}, localKeyValue->key, itemLocal);
                {{/isPrimitiveType}}
                }
            }
        {{/isMapContainer}}
    {{/isContainer}}
    {{^required}}
       }
    {{/required}}

{{/vars}}
end:
    return item;
}

OpenAPI_{{classname}}_t *OpenAPI_{{classname}}_parseFromJSON(cJSON *{{classname}}JSON)
{
    OpenAPI_{{classname}}_t *{{classname}}_local_var = NULL;
{{#vars}}
    cJSON *{{{name}}} = cJSON_GetObjectItemCaseSensitive({{classname}}JSON, "{{{baseName}}}");
    {{#required}}
        if (!{{{name}}}) {
            ogs_error("OpenAPI_{{classname}}_parseFromJSON() failed [{{{name}}}]");
            goto end;
        }
    {{/required}}

    {{^isContainer}}
        {{#isPrimitiveType}}
            {{#isEnum}}
                OpenAPI_{{classVarName}}_{{name}}_e {{name}}Variable;
                {{^required}}if ({{{name}}}) { {{/required}}
                if (!cJSON_IsString({{{name}}})) {
                    ogs_error("OpenAPI_{{classname}}_parseFromJSON() failed [{{{name}}}]");
                    goto end;
                }
                {{name}}Variable = OpenAPI_{{name}}{{classname}}_FromString({{{name}}}->valuestring);
            {{/isEnum}}
            {{^isEnum}}
                {{#isNumeric}}
                    {{^required}}if ({{{name}}}) { {{/required}}
                    if (!cJSON_IsNumber({{{name}}})) {
                        ogs_error("OpenAPI_{{classname}}_parseFromJSON() failed [{{{name}}}]");
                        goto end;
                    }
                {{/isNumeric}}
                {{#isBoolean}}
                    {{^required}}if ({{{name}}}) { {{/required}}
                    if (!cJSON_IsBool({{{name}}})) {
                        ogs_error("OpenAPI_{{classname}}_parseFromJSON() failed [{{{name}}}]");
                        goto end;
                    }
                {{/isBoolean}}
                {{#isString}}
                    {{^required}}if ({{{name}}}) { {{/required}}
                    if (!cJSON_IsString({{{name}}})) {
                        ogs_error("OpenAPI_{{classname}}_parseFromJSON() failed [{{{name}}}]");
                        goto end;
                    }
                {{/isString}}
            {{/isEnum}}
            {{#isByteArray}}
                {{^required}}if ({{{name}}}) { {{/required}}
                if (!cJSON_IsNumber({{{name}}})) {
                    ogs_error("OpenAPI_{{classname}}_parseFromJSON() failed [{{{name}}}]");
                    goto end;
                }
            {{/isByteArray}}
            {{#isBinary}}
                OpenAPI_binary_t* decoded_str_{{{name}}} = OpenAPI_malloc(sizeof(OpenAPI_binary_t));
                {{^required}}if ({{{name}}}) { {{/required}}
                if (!cJSON_IsString({{{name}}})) {
                    ogs_error("OpenAPI_{{classname}}_parseFromJSON() failed [{{{name}}}]");
                    goto end;
                }
                decoded_str_{{{name}}}->data = OpenAPI_base64decode({{{name}}}->valuestring, strlen({{{name}}}->valuestring), &decoded_str_{{{name}}}->len);
                if (!decoded_str_{{{name}}}->data) {
                    ogs_error("OpenAPI_{{classname}}_parseFromJSON() failed [{{{name}}}]");
                    goto end;
                }
            {{/isBinary}}
            {{#isDate}}
                {{^required}}if ({{{name}}}) { {{/required}}
                if (!cJSON_IsString({{{name}}})) {
                    ogs_error("OpenAPI_{{classname}}_parseFromJSON() failed [{{{name}}}]");
                    goto end;
                }
            {{/isDate}}
            {{#isDateTime}}
                {{^required}}if ({{{name}}}) { {{/required}}
                if (!cJSON_IsString({{{name}}})) {
                    ogs_error("OpenAPI_{{classname}}_parseFromJSON() failed [{{{name}}}]");
                    goto end;
                }
            {{/isDateTime}}
        {{/isPrimitiveType}}
        {{^isPrimitiveType}}
            {{#isEnum}}
                OpenAPI_{{complexType}}_e {{name}}Variable;
                {{^required}}if ({{{name}}}) { {{/required}}
                if (!cJSON_IsString({{{name}}})) {
                    ogs_error("OpenAPI_{{classname}}_parseFromJSON() failed [{{{name}}}]");
                    goto end;
                }
                {{name}}Variable = OpenAPI_{{complexType}}_FromString({{{name}}}->valuestring);
            {{/isEnum}}
            {{^isEnum}}
                {{#isModel}}
                    {{^isFreeFormObject}}OpenAPI_{{complexType}}{{/isFreeFormObject}}{{#isFreeFormObject}}OpenAPI_object{{/isFreeFormObject}}_t *{{name}}_local_nonprim = NULL;
                    {{^required}}if ({{{name}}}) { {{/required}}
                    {{{name}}}_local_nonprim = OpenAPI_{{complexType}}{{#isFreeFormObject}}object{{/isFreeFormObject}}_parseFromJSON({{{name}}});
                {{/isModel}}
                {{#isUuid}}
                    {{^required}}if ({{{name}}}) { {{/required}}
                    if (!cJSON_IsString({{{name}}})) {
                        ogs_error("OpenAPI_{{classname}}_parseFromJSON() failed [{{{name}}}]");
                        goto end;
                    }
                {{/isUuid}}
                {{#isEmail}}
                    {{^required}}if ({{{name}}}) { {{/required}}
                    if (!cJSON_IsString({{{name}}})) {
                        ogs_error("OpenAPI_{{classname}}_parseFromJSON() failed [{{{name}}}]");
                        goto end;
                    }
                {{/isEmail}}
                {{#isFreeFormObject}}
                    OpenAPI_object_t *{{name}}_local_object = NULL;
                    {{^required}}if ({{{name}}}) { {{/required}}
                    {{{name}}}_local_object = OpenAPI_object_parseFromJSON({{{name}}});
                {{/isFreeFormObject}}
            {{/isEnum}}
        {{/isPrimitiveType}}
    {{/isContainer}}
    {{#isContainer}}
        {{#isListContainer}}
            {{#isPrimitiveType}}
                {{^isEnum}}
                    OpenAPI_list_t *{{{name}}}List;
                    {{^required}}if ({{{name}}}) { {{/required}}
                    cJSON *{{{name}}}_local;
                    if (!cJSON_IsArray({{{name}}})) {
                        ogs_error("OpenAPI_{{classname}}_parseFromJSON() failed [{{{name}}}]");
                        goto end;
                    }
                    {{{name}}}List = OpenAPI_list_create();

                    cJSON_ArrayForEach({{{name}}}_local, {{{name}}}) {
                    {{#items}}
                        {{#isString}}
                            if (!cJSON_IsString({{{name}}}_local)) {
                                ogs_error("OpenAPI_{{classname}}_parseFromJSON() failed [{{{name}}}]");
                                goto end;
                            }
                            OpenAPI_list_add({{{name}}}List , ogs_strdup({{{name}}}_local->valuestring));
                        {{/isString}}
                        {{#isNumeric}}
                            if (!cJSON_IsNumber({{{name}}}_local)) {
                                ogs_error("OpenAPI_{{classname}}_parseFromJSON() failed [{{{name}}}]");
                                goto end;
                            }
                            OpenAPI_list_add({{{name}}}List , &{{{name}}}_local->valuedouble);
                        {{/isNumeric}}
                        {{#isBoolean}}
                            if (!cJSON_IsBool({{{name}}}_local)) {
                                ogs_error("OpenAPI_{{classname}}_parseFromJSON() failed [{{{name}}}]");
                                goto end;
                            }
                            OpenAPI_list_add({{{name}}}List , {{{name}}}_local->valueint);
                        {{/isBoolean}}
                    {{/items}}
                    }
                {{/isEnum}}
            {{/isPrimitiveType}}
            {{^isPrimitiveType}}
                {{^isEnum}}
                    OpenAPI_list_t *{{{name}}}List;
                    {{^required}}if ({{{name}}}) { {{/required}}
                    cJSON *{{{name}}}_local_nonprimitive;
                    if (!cJSON_IsArray({{{name}}})){
                        ogs_error("OpenAPI_{{classname}}_parseFromJSON() failed [{{{name}}}]");
                        goto end;
                    }

                    {{{name}}}List = OpenAPI_list_create();

                    cJSON_ArrayForEach({{{name}}}_local_nonprimitive, {{{name}}} ) {
                        if (!cJSON_IsObject({{{name}}}_local_nonprimitive)) {
                            ogs_error("OpenAPI_{{classname}}_parseFromJSON() failed [{{{name}}}]");
                            goto end;
                        }
                        {{#isEnum}}{{#items}}{{datatypeWithEnum}}_e {{/items}}{{/isEnum}}{{^isEnum}}OpenAPI_{{complexType}}_t *{{/isEnum}}{{{name}}}Item = OpenAPI_{{complexType}}_parseFromJSON({{{name}}}_local_nonprimitive);

                        OpenAPI_list_add({{{name}}}List, {{#isEnum}}{{#items}}(void *){{/items}}{{/isEnum}}{{{name}}}Item);
                    }
                {{/isEnum}}
                {{#isEnum}}
                    OpenAPI_list_t *{{{name}}}List;
                    {{^required}}if ({{{name}}}) { {{/required}}
                    cJSON *{{{name}}}_local_nonprimitive;
                    if (!cJSON_IsArray({{{name}}})) {
                        ogs_error("OpenAPI_{{classname}}_parseFromJSON() failed [{{{name}}}]");
                        goto end;
                    }

                    {{{name}}}List = OpenAPI_list_create();

                    cJSON_ArrayForEach({{{name}}}_local_nonprimitive, {{{name}}} ) {
                        if (!cJSON_IsString({{{name}}}_local_nonprimitive)){
                            ogs_error("OpenAPI_{{classname}}_parseFromJSON() failed [{{{name}}}]");
                            goto end;
                        }

                        OpenAPI_list_add({{{name}}}List, (void *)OpenAPI_{{{complexType}}}_FromString({{{name}}}_local_nonprimitive->valuestring));
                    }
                {{/isEnum}}
            {{/isPrimitiveType}}
        {{/isListContainer}}
        {{#isMapContainer}}
            OpenAPI_list_t *{{{name}}}List;
            {{^required}}if ({{{name}}}) { {{/required}}
            cJSON *{{{name}}}_local_map;
            if (!cJSON_IsObject({{{name}}})) {
                ogs_error("OpenAPI_{{classname}}_parseFromJSON() failed [{{{name}}}]");
                goto end;
            }
            {{{name}}}List = OpenAPI_list_create();
            OpenAPI_map_t *localMapKeyPair = NULL;
            cJSON_ArrayForEach({{{name}}}_local_map, {{{name}}}) {
                cJSON *localMapObject = {{{name}}}_local_map;
                {{#isPrimitiveType}}
                    {{#isString}}
                        if (!cJSON_IsString(localMapObject)) {
                            ogs_error("OpenAPI_{{classname}}_parseFromJSON() failed [{{{name}}}]");
                            goto end;
                        }
                        localMapKeyPair = OpenAPI_map_create(ogs_strdup(localMapObject->string),ogs_strdup(localMapObject->valuestring));
                    {{/isString}}
                    {{#isBoolean}}
                        if (!cJSON_IsBool(localMapObject)) {
                            ogs_error("OpenAPI_{{classname}}_parseFromJSON() failed [{{{name}}}]");
                            goto end;
                        }
                        localMapKeyPair = OpenAPI_map_create(ogs_strdup(localMapObject->string), &localMapObject->valueint);
                    {{/isBoolean}}
                    {{#isNumeric}}
                        if (!cJSON_IsNumber(localMapObject)) {
                            ogs_error("OpenAPI_{{classname}}_parseFromJSON() failed [{{{name}}}]");
                            goto end;
                        }
                        localMapKeyPair = OpenAPI_map_create(ogs_strdup(localMapObject->string),&localMapObject->valuedouble );
                    {{/isNumeric}}
                {{/isPrimitiveType}}
                {{^isPrimitiveType}}
                    if (!cJSON_IsObject({{{name}}}_local_map)) {
                        ogs_error("OpenAPI_{{classname}}_parseFromJSON() failed [{{{name}}}]");
                        goto end;
                    }
                    localMapKeyPair = OpenAPI_map_create(
                        localMapObject->string, OpenAPI_{{complexType}}_parseFromJSON(localMapObject));
                {{/isPrimitiveType}}
                OpenAPI_list_add({{{name}}}List , localMapKeyPair);
            }
        {{/isMapContainer}}
    {{/isContainer}}
    {{^required}}
    }
    {{/required}}

{{/vars}}
    {{classname}}_local_var = OpenAPI_{{classname}}_create (
{{#vars}}
    {{^isContainer}}
        {{^isPrimitiveType}}
            {{#isEnum}}
                {{^required}}{{{name}}} ? {{/required}}{{{name}}}Variable{{^required}} : 0{{/required}}{{#hasMore}},{{/hasMore}}
            {{/isEnum}}
            {{^isEnum}}
                {{#isModel}}
                    {{^required}}{{{name}}} ? {{/required}}{{{name}}}_local_nonprim{{^required}} : NULL{{/required}}{{#hasMore}},{{/hasMore}}
                {{/isModel}}
                {{#isUuid}}
                    {{^required}}{{{name}}} ? {{/required}}ogs_strdup({{{name}}}->valuestring){{^required}} : NULL{{/required}}{{#hasMore}},{{/hasMore}}
                {{/isUuid}}
                {{#isEmail}}
                    {{^required}}{{{name}}} ? {{/required}}ogs_strdup({{{name}}}->valuestring){{^required}} : NULL{{/required}}{{#hasMore}},{{/hasMore}}
                {{/isEmail}}
                {{#isFreeFormObject}}
                    {{^required}}{{{name}}} ? {{/required}}{{{name}}}_local_object{{^required}} : NULL{{/required}}{{#hasMore}},{{/hasMore}}
                {{/isFreeFormObject}}
            {{/isEnum}}
        {{/isPrimitiveType}}
        {{#isPrimitiveType}}
            {{#isEnum}}
                {{^required}}{{{name}}} ? {{/required}}{{name}}Variable{{^required}} : 0{{/required}}{{#hasMore}},{{/hasMore}}
            {{/isEnum}}
            {{^isEnum}}
                {{#isNumeric}}
                    {{^required}}{{{name}}} ? {{/required}}{{{name}}}->valuedouble{{^required}} : 0{{/required}}{{#hasMore}},{{/hasMore}}
                {{/isNumeric}}
                {{#isBoolean}}
                    {{^required}}{{{name}}} ? {{/required}}{{{name}}}->valueint{{^required}} : 0{{/required}}{{#hasMore}},{{/hasMore}}
                {{/isBoolean}}
                {{#isString}}
                    {{^required}}{{{name}}} ? {{/required}}ogs_strdup({{{name}}}->valuestring){{^required}} : NULL{{/required}}{{#hasMore}},{{/hasMore}}
                {{/isString}}
            {{/isEnum}}
            {{#isByteArray}}
                {{^required}}{{{name}}} ? {{/required}}{{{name}}}->valueint{{^required}} : 0{{/required}}{{#hasMore}},{{/hasMore}}
            {{/isByteArray}}
            {{#isBinary}}
                {{^required}}{{{name}}} ? {{/required}}decoded_str_{{{name}}}{{^required}} : NULL{{/required}}{{#hasMore}},{{/hasMore}}
            {{/isBinary}}
            {{#isDate}}
                {{^required}}{{{name}}} ? {{/required}}ogs_strdup({{{name}}}->valuestring){{^required}} : NULL{{/required}}{{#hasMore}},{{/hasMore}}
            {{/isDate}}
            {{#isDateTime}}
                {{^required}}{{{name}}} ? {{/required}}ogs_strdup({{{name}}}->valuestring){{^required}} : NULL{{/required}}{{#hasMore}},{{/hasMore}}
            {{/isDateTime}}
        {{/isPrimitiveType}}
    {{/isContainer}}
    {{#isContainer}}
        {{#isListContainer}}
            {{^required}}{{{name}}} ? {{/required}}{{{name}}}List{{^required}} : NULL{{/required}}{{#hasMore}},{{/hasMore}}
        {{/isListContainer}}
        {{#isMapContainer}}
            {{^required}}{{{name}}} ? {{/required}}{{{name}}}List{{^required}} : NULL{{/required}}{{#hasMore}},{{/hasMore}}
        {{/isMapContainer}}
    {{/isContainer}}
{{/vars}}
        );

    return {{classname}}_local_var;
end:
    return NULL;
}

OpenAPI_{{classname}}_t *OpenAPI_{{classname}}_copy(OpenAPI_{{classname}}_t *dst, OpenAPI_{{classname}}_t *src)
{
    cJSON *item = NULL;
    char *content = NULL;

    ogs_assert(src);
    item = OpenAPI_{{classname}}_convertToJSON(src);
    if (!item) {
    ogs_error("OpenAPI_{{classname}}_convertToJSON() failed");
        return NULL;
    }

    content = cJSON_Print(item);
    cJSON_Delete(item);

    if (!content) {
        ogs_error("cJSON_Print() failed");
        return NULL;
    }

    item = cJSON_Parse(content);
    ogs_free(content);
    if (!item) {
        ogs_error("cJSON_Parse() failed");
        return NULL;
    }

    OpenAPI_{{classname}}_free(dst);
    dst = OpenAPI_{{classname}}_parseFromJSON(item);
    cJSON_Delete(item);

    return dst;
}
{{/isEnum}}
{{/model}}{{/models}}
